﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace CXMLStudioIDE.Common.EntityProperties
{
    public class PropertySetCollection : CollectionBase
    {
        #region Method Implimentation
            /// <summary>
            /// Add PropertyClass to Collectionbase List
            /// </summary>
            /// <param name="Value"></param>
            public void Add(PropertySet Value)
            {
                base.List.Add(Value);
            }

            /// <summary>
            /// Remove item from List
            /// </summary>
            /// <param name="Name"></param>
            public void Remove(string Name)
            {
                foreach (PropertySet prop in base.List)
                {
                    if (prop.EntityName == Name)
                    {
                        base.List.Remove(prop);
                        return;
                    }
                }
            }

            /// <summary>
            /// Get a specific entity property Set by name
            /// </summary>
            /// <param name="sEntityName"></param>
            /// <returns></returns>
            public PropertySet GetByName(string sEntityName)
            {
                foreach (PropertySet prop in base.List)
                {
                    if (prop.EntityName == sEntityName)
                        return prop;
                }
                return null;
            }

            public PropertySet GetByContextAndName(DisplayContext context, string sEntityName)
            {
                foreach (PropertySet prop in this)
                {
                    if (prop.DisplayContext == context &&
                            prop.EntityName == sEntityName)
                        return prop;
                }
                return null;            
            }

            public PropertySet GetByControlName(DisplayContext context, string sEntityName)
            {
                foreach (PropertySet prop in this)
                {
                    if (prop.DisplayContext == context &&
                            prop.EntityName == sEntityName)
                        return prop;
                }
                return null;
            }
            /// <summary>
            /// Indexer
            /// </summary>
            public PropertySet this[int index]
            {
                get
                {
                    return (PropertySet)base.List[index];
                }
                set
                {
                    base.List[index] = (PropertySet)value;
                }
            }
        #endregion
    }
}
